from flask import *
from flask_mongoengine import MongoEngine
import datetime

app = Flask(__name__)
app.config['MONGODB_SETTINGS'] = {
    'db' : 'Unicon',
    'host' : '127.0.0.1',
    'port' : 27017
}
db = MongoEngine(app)

class News(db.Document):
    title = db.StringField(required=True,max_length=200)
    content = db.StringField(required=True,max_lrngth=200)
    img_url= db.StringField()
    is_valid = db.BooleanField(default=True)
    create_at = db.DateTimefield(default=datetime.now())
    update_at = db.DateTimefield(default=datetime.now())
    
    meta = {
        'collection' : 'News',
        'ordering':['-create_at']

    }

# class User(db.Document):
#     email = db.StringField(required=True)
#     frist_name = db.StringField(max_lenth=50)
#     last_name = db.StringField(max_lenth=50)





@app.route('/')
def index():
    news_list = News.objects.all()
    return rander_template('index.html',news_list=news_list)

if __name__ == '__main__':
    app.run(debug=True)